package com.tarena.lbs.basic.web.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tarena.lbs.basic.web.mapper.UserTagsMapper;
import com.tarena.lbs.pojo.basic.po.UserTagsPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

//mybatis-plus除了实现了持久层的接口功能 还实现了业务层的功能 可以封装调用更多的对数据CRUD方法比如批量
//ServiceImpl需要我们传递2个泛型<M,T> M表示操作数据的mapper接口 T数据实体类
@Repository
public class UserTagsRepository extends ServiceImpl<UserTagsMapper, UserTagsPO> {
    @Autowired
    private UserTagsMapper userTagsMapper;
    //04、用户绑定关联标签
    public void deleteByUserId(Integer userId) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        userTagsMapper.delete(queryWrapper);
        //delete from lbs_user_
        // tags where user_id=#{}
    }
    public List<UserTagsPO> getUserTagsByUserId(Integer userId) {
        QueryWrapper<UserTagsPO> queryWrapper=new QueryWrapper<>();
        //select * from lbs_user_tags where user_id=#{userId}
        queryWrapper.eq("user_id",userId);
        return userTagsMapper.selectList(queryWrapper);
    }
}

